home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / util / libs / chunky_dev.lha / chunky_dev / Demos / Basics / FirstSteps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-15  |  3.7 KB  |  124 lines

  1. //
  2. // FirstSteps.c
  3. //
  4. // This example shows how to do the basic stuff with chunky.library.
  5. // Such basic stuff includes allocating buffers, display chunky data
  6. // on a screen, and freeing buffers.
  7. //
  8. // (c) 1999 Rosande Limited, all rights reserved.
  9. // PUBLIC DOMAIN
  10. //
  11. // http://www.irrelevant.org/~oondy/chunky/
  12.  
  13. #include <exec/types.h>
  14. #include <clib/chunky_protos.h>
  15. #include <pragma/chunky_lib.h>
  16. #include <exec/libraries.h>
  17. #include <pragma/exec_lib.h>
  18. #include <intuition/intuition.h>
  19. #include <pragma/intuition_lib.h>
  20. #include <pragma/graphics_lib.h>
  21. #include <stdio.h>
  22.  
  23. #include "/_shared/loadcp.h"
  24. #include "/_shared/screen.h"
  25. #include "/_shared/waitbutton.h"
  26.  
  27. // The chunky buffer structure - a ChunkyPort, so called because
  28. // RastPort's and ChunkyPort's - see? :)
  29. struct ChunkyPort *cp = NULL;
  30.  
  31. struct Library *ChunkyBase;
  32. // dos.library etc are all opened by StormC - isn't that nice :)
  33.  
  34. UBYTE *ImageBuffer = NULL;
  35. void *ColourPalette = NULL;
  36.  
  37. void TheMainDemo(void);
  38.  
  39. main()
  40. {
  41.   // Open the chunky.library
  42.   printf("\nSimple chunky.library Demo\n"
  43.          "Displays a chunky image on a screen, waiting for you to click\n"
  44.          "the close button of the window.\n(c) 1999 Rosande Limited.  PD.\n\n");
  45.  
  46.   if(ChunkyBase = OpenLibrary("chunky.library", 4))
  47.   {
  48.     // Open a screen
  49.     printf("Load the colour table...\n");
  50.     if(ColourPalette = DEMO_LoadRGB32("/_shared/320x200.col"))
  51.     {
  52.       printf("Open the screen...\n");
  53.       if(DEMO_OpenScreen(320, 200, NULL, ColourPalette))
  54.       {
  55.         // Load in the example image
  56.         printf("Load the example 320x200 image...\n");
  57.         if(ImageBuffer = DEMO_LoadChunky("/_shared/320x200.chk", 320, 200))
  58.         {
  59.           // Go!
  60.           TheMainDemo();
  61.         }
  62.       }
  63.     }
  64.     printf("Freeing buffers...\n");
  65.     if(ImageBuffer) DEMO_FreeChunky(ImageBuffer);
  66.     if(DemoScreen) DEMO_CloseScreen();
  67.     if(ColourPalette) DEMO_FreeRGB32(ColourPalette);
  68.     if(ChunkyBase) CloseLibrary(ChunkyBase);
  69.   }
  70.   else
  71.   {
  72.     printf("\n ! Can't open chunky.library V4! \n");
  73.   }
  74.   printf("Done!\n");
  75. }
  76.  
  77. void TheMainDemo(void)
  78. {
  79.   // Allocate the ChunkyPort
  80.   printf("Allocating ChunkyPort...\n");
  81.   if(cp = CHK_InitChunky(320, 200))
  82.   {
  83.     // Now, copy the chunky data we loaded off disk into the ChunkyPort
  84.     CopyMem(ImageBuffer, cp->cp_Chunky, (320*200));
  85.     //
  86.     // We have a ChunkyPort which we can display on screen.
  87.     // Now that the screen is open, we need to tell chunky.library
  88.     // what type of screen we have opened so it knows whether or not
  89.     // to use custom C2P for AGA or the drawing functions of the
  90.     // graphics card.
  91.     //
  92.     // We tell chunky.library what to do via the CHK_ChooseHardwareMode()
  93.     // command.  It requires a ModeID - the same ID used passed to
  94.     // OpenScreenTagList() and SA_ModeID.
  95.     //
  96.     // IT IS IMPORTANT TO CALL CHK_CHOOSEHARDWAREMODE()!  If this call
  97.     // isn't called in your program,  chunky.library defaults to using
  98.     // custom C2P for AGA - meaning your program WILL FAIL ON GRAPHICS
  99.     // BOARDS!
  100.     //
  101.     // If you don't know the ModeID of the screen, use the graphics.library
  102.     // call GetVPModeID() as shown below.  Otherwise,  use the result you
  103.     // got from your asl.library ScreenModeRequest struct or whatever.
  104.     //
  105.     CHK_ChooseHardwareMode(GetVPModeID(&DemoScreen->ViewPort));
  106.     //
  107.     // Now we can draw the image on  the screen...
  108.     printf("Drawing ChunkyPort...\n");
  109.     CHK_DrawChunky(cp, DemoWindow->RPort, 0, 0);
  110.     //
  111.     // Tada! :)  Now just wait for the close gadget to be pressed.
  112.     printf("Hit that close gadget!\n");
  113.     DEMO_WaitForCloseGadget();
  114.     //
  115.     // Free the chunky...
  116.     printf("Freeing ChunkyPort...\n");
  117.     CHK_FreeChunky(cp);
  118.   }
  119.   else
  120.   {
  121.     printf("No memory!\n");
  122.   }
  123. }
  124.